package com.kma.summer2012.client.presenters.breadcrumbs;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.kma.summer2012.client.SiteMap;
import com.kma.summer2012.client.presenters.Presenter;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: EUGENE
 * Date: 3/6/13
 * Time: 3:19 AM
 * To change this template use File | Settings | File Templates.
 */
public class BreadCrumbsPresenter implements ValueChangeHandler, Presenter {
    private final Display display;

    public interface Display {
        Widget asWidget();

        void setPath(List<SiteMap.Node> list);
    }

    @Override
    public void go(HasWidgets container) {
        History.addValueChangeHandler(this);
    }

    @Override
    public void onValueChange(ValueChangeEvent valueChangeEvent) {
        List<SiteMap.Node> path = SiteMap.getInstance().getPath(History.getToken());
        this.display.setPath(path);
    }

    public BreadCrumbsPresenter(Display display) {
        this.display = display;
    }

}
